CC=arm-apple-darwin-gcc
LD=$(CC)

APPSOURCES =	DevEngine.mm \
					FBUIController.mm	\
					FreeBoardPreferences.mm	\
					SpicyButtonBar.mm \
					SpicyIcon.mm \
					Debug.mm

LIBSOURCES = 	Initialization.m \
					Debug.m

APP = FreeBoard

%.o:    %.m
		$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

all: ${APP} ${APP}.dylib

install-all: install install-plist install-library install-prefs

${APP}: ${APPSOURCES}
	$(LD) -fobjc-call-cxx-cdtors -bundle -g3 -O2 -Wall -Werror -o $(APP)Framework/$@ $(filter %.mm,$^) -framework CoreFoundation -framework Foundation -framework UIKit -lobjc -fobjc-exceptions -flat_namespace -undefined suppress -I../uicaboodle.m

${APP}.dylib: ${LIBSOURCES}
	$(LD) -dynamiclib -g3 -O2 -Wall -Werror -o $(APP)Framework/$@ $(filter %.m,$^) -framework CoreFoundation -framework Foundation -lobjc -init _IBInitialize

cleanup:
		mv $(APP).framework $(APP)Framework

install:
	mv $(APP)Framework $(APP).framework
	scp -r $(APP).framework root@mambo:/Library/Frameworks/
	mv $(APP).framework $(APP)Framework

install-plist:
	scp com.apple.SpringBoard.plist root@mambo:/System/Library/LaunchDaemons/com.apple.SpringBoard.plist

install-prefs:
	scp com.thespicychicken.FreeBoard.plist root@mambo:/var/mobile/Library/Preferences/com.thespicychicken.FreeBoard.plist

install-library:
	scp -r LibraryFolder root@mambo:/var/mobile/Library/FreeBoard

revert:
	scp com.apple.SpringBoard.plist.revert root@mambo:/System/Library/LaunchDaemons/com.apple.SpringBoard.plist

release:
	cp -r $(APP)Framework Release/FreeBoard-Latest/$(APP).framework

clean:
	rm FreeBoardFramework/FreeBoard
	rm FreeBoardFramework/FreeBoard.dylib
